package com.redteam.data.beans;

import com.redteam.data.enums.Endorsement;
import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

/**
 * A java bean for pilot
 * @author Anthony Ferrari
 * @author Teddy Karam
 */
public class Pilot extends Person implements com.redteam.interfaces.Pilot, Serializable {

    private int flightHours;
    private List<Endorsement> endorsements;
    private List<Reservation> reservations;
    private static final long serialVersionUID = 1L;

    /**
     * Pilot full constructor
     * @param id
     * @param firstName
     * @param middleName
     * @param lastName
     * @param street
     * @param city
     * @param state
     * @param zipCode
     * @param email
     * @param fBOId
     * @param birthdate
     * @param homePhone
     * @param cellPhone
     * @param workPhone
     * @param gender
     * @param flightHours
     * @param endorse
     * @param type
     * @param userName
     * @param password
     */
    public Pilot(long id, String firstName, String middleName, String lastName, String street, String city, String state, String zipCode,
            String email, long fBOId, Date birthdate, String homePhone, String cellPhone, String workPhone, String gender, int flightHours, String type, String userName, String password) {
        super(id, firstName, middleName, lastName, street, city, state, zipCode, email, fBOId, birthdate, homePhone, cellPhone, workPhone, gender, type, userName, password);

        this.endorsements = new ArrayList<Endorsement>();
        this.reservations = new ArrayList<Reservation>();
        this.setFlightHours(flightHours);

    }

    /**
     * Default bean constructor
     */
    public Pilot() {
        super();
        this.endorsements = new ArrayList<Endorsement>();
        this.reservations = new ArrayList<Reservation>();
    }

    /**
     * @inheritDoc
     */
    @Override
    public final int getFlightHours() {
        return flightHours;
    }

    /**
     * @inheritDoc
     */
    @Override
    public final void setFlightHours(int flightHours) {
        this.flightHours = flightHours;
    }

    /**
     * @inheritDoc
     */
    @Override
    public final List<Reservation> getReservations() {
        return reservations;
    }

    /**
     * @inheritDoc
     */
    @Override
    public final void addReservations(List<Reservation> reservation) {
        this.reservations.addAll(reservation);
    }

    /**
     * @inheritDoc
     */
    @Override
    public List<String> getEndorsements() {
        List<String> endorsementList = new ArrayList<String>();
        if (this.endorsements != null) {
            for (Endorsement e : endorsements) {
                endorsementList.add(e.toString());
            }
        }
        return endorsementList;
    }

    /**
     * @inheritDoc
     */
    @Override
    public void setEndorsements(List<String> endorsement) {
        if (endorsement != null) {
            for (String s : endorsement) {
                Endorsement e = Endorsement.valueOf(s);
                endorsements.add(e);
            }
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Pilot other = (Pilot) obj;
        if (this.flightHours != other.flightHours) {
            return false;
        }
        if (this.endorsements != other.endorsements && (this.endorsements == null || !this.endorsements.equals(other.endorsements))) {
            return false;
        }
        if (this.reservations != other.reservations && (this.reservations == null || !this.reservations.equals(other.reservations))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 43 * hash + this.flightHours;
        hash = 43 * hash + (this.endorsements != null ? this.endorsements.hashCode() : 0);
        hash = 43 * hash + (this.reservations != null ? this.reservations.hashCode() : 0);
        return hash;
    }
}
